package com.sc.admin.config;

import com.sc.admin.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: Sunk 673116067@qq.com
 * @Date: 2018/4/19 16:50
 * @Description:
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    //由于拦截器中Autowired无法注入，因为拦截器加载的时间点在springcontext之前，所以在拦截器中注入自然为null
    //在这里提前在IOC容器中进行实例化，达到能够注入的目的
    @Bean
    LoginInterceptor localInterceptor() {
        return new LoginInterceptor();
    }

    /**
     * 注册 拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localInterceptor());
    }
}
